//
//  String+Extension.swift
//  BaoKeSwift
//
//  Created by geek-duan on 2017/10/9.
//  Copyright © 2017年 geek-duan. All rights reserved.
//

import UIKit

extension String {
    
    // MARK: - 转换数值格式
    static func CountNum(num: Double) ->String {
        var numStr = ""
        switch num {
        case 0..<1000.0:
            numStr = "\(Int(num))"
        case 1000.0..<10000.0:
            numStr = String(format: "%.1fk", num / 1000.0)
        default:
            numStr = String(format: "%.1fw", num / 10000.0)
        }
        return numStr
    }
    
    // MARK: - 根据字符串宽度计算高
    func calculateHeight(font: UIFont, width: CGFloat) -> CGFloat {
        let size = (self as NSString).boundingRect(with: CGSize.init(width: width, height: .greatestFiniteMagnitude), options: [.usesFontLeading, .usesLineFragmentOrigin], attributes: [.font: font], context: nil).size
        return size.height + 10
    }
}
